package example.documentbased.editorModule.models
{
	import example.documentbased.mainModule.models.vo.DocumentVO;
	import example.documentbased.mainModule.models.vo.EditorVO;
	
	import mx.collections.ArrayList;
	
	import org.etherframework.common.mediation.IMediationProvider;
	import org.etherframework.common.utils.OU;

	public class EditorModuleModel implements IMediationProvider
	{
		private var _editor:EditorVO;
		private var _currentDocument:DocumentVO;
		private var _lastSavedDocument:DocumentVO;
		private var _editedDocuments:ArrayList = new ArrayList();
		private var _openedDocuments:ArrayList = new ArrayList();
		private var _menuItems:Array = [];

		public function openDocument(document:DocumentVO):void
		{
			var doc:DocumentVO = OU.getItem(_openedDocuments, 
				"uid", document.uid) as DocumentVO;
			
			if (!doc)
			{
				_openedDocuments.addItem(document);
			}
		}
		
		public function closeDocument(document:DocumentVO):void
		{
			var doc:DocumentVO = OU.getItem(_openedDocuments, 
				"uid", document.uid) as DocumentVO;
			
			if (doc)
			{
				_openedDocuments.removeItem(doc);
			}
			
			uneditDocument(document);
		}
		
		public function editDocument(document:DocumentVO):void
		{
			var doc:DocumentVO = OU.getItem(_editedDocuments, 
				"uid", document.uid) as DocumentVO;
			
			if (!doc)
			{
				_editedDocuments.addItem(document);
			}
		}
		
		public function uneditDocument(document:DocumentVO):void
		{
			var doc:DocumentVO = OU.getItem(_editedDocuments, 
				"uid", document.uid) as DocumentVO;
			
			if (doc)
			{
				_editedDocuments.removeItem(doc);
			}
		}
		
		public function getIsEditedDocument(document:DocumentVO):Boolean
		{
			return Boolean(OU.getItem(_editedDocuments, "uid", document.uid));
		}
		
		public function get editedDocuments():ArrayList { return _editedDocuments; }
		public function set editedDocuments(value:ArrayList):void { _editedDocuments = value; }
		
		public function get openedDocuments():ArrayList { return _openedDocuments; }
		public function set openedDocuments(value:ArrayList):void { _openedDocuments = value; }
		
		public function get currentDocument():DocumentVO { return _currentDocument; }
		public function set currentDocument(value:DocumentVO):void { _currentDocument = value; }
		
		public function get lastSavedDocument():DocumentVO { return _lastSavedDocument; }
		public function set lastSavedDocument(value:DocumentVO):void { _lastSavedDocument = value; }
		
		public function get editor():EditorVO { return _editor; }
		public function set editor(value:EditorVO):void { _editor = value; }
		
		public function get menuItems():Array { return _menuItems; }
		public function set menuItems(value:Array):void { _menuItems = value; }
	}
}